#!/usr/bin/wish
# vue_metdisp source
# Basic font for button, menus and labels
# Product of NASA/GSFC Geodedic VLBI (2004)
# to be incorporated into the VLBI Field System.
  # Window manager configurations
  set ICONDIR /usr2/fs/fsvue/images
  set ROOTBIN /usr2/prog/

# Use this size of fonts for the information icon, or help.

  global tkVersion
  wm positionfrom . user
  wm sizefrom . ""
  wm maxsize . 1152 900  
  wm iconbitmap . @$ICONDIR/vlb.icon
  wm iconposition . 1200 0
  wm iconname . {fsvue}
#  wm geometry . +5+25
  wm title . {MET3}
  set w .
  $w config -cursor {top_left_arrow black white}

  set bfont {-*-lucida-medium-r-*-sans-18-*-*-*-*-*-*-*}

  proc balloon_help {w msg} {
      bind $w <Enter> "after 1000 \"balloon_aux %W [list $msg]\""
      bind $w <Leave> "after cancel \"balloon_aux %W [list $msg]\"
                        after 100 {catch {destroy .balloon_help}}"
  }

proc startwx {} {

 set LIBDIR /usr2/fs/fsvue/lib
      set ibfont [open "|/bin/sh -c \"cat $LIBDIR/my_font; :\""]
      set bfont [gets $ibfont]
      catch {close $ibfont}

frame .m1 \
        -bg {navy} \
        -borderwidth {2} \
        -relief {groove} 

frame .m2 \
        -bg {navy} \
        -borderwidth {2} \
        -relief {groove} 

button .m2.r -text "Reset MET3" -relief {raise} -font $bfont -background black -fg white -command {exec ./metwind reset}
button .m2.c -text "Set mBar" -relief {raise} -font $bfont -background black -fg white -command {exec ./metwind chan}
button .m2.b -text "Set Bar" -relief {raise} -font $bfont -background black -fg white -command {exec ./metwind bar}

label .m1.label4 -text "UT Time" -font $bfont -bg blue -fg white
label .m1.result4 -width 20 -relief sunken -font $bfont -textvariable result4
label .m1.label1 -text "Temperature" -font $bfont -bg blue -fg white
label .m1.result1 -width 8 -relief sunken -font $bfont -textvariable result1
label .m1.label2 -text "Pressure" -font $bfont -bg blue -fg white
label .m1.result2 -width 8 -relief sunken -font $bfont -textvariable result2
label .m1.label3 -text "Humidity" -font $bfont -bg blue -fg white
label .m1.result3 -width 8 -relief sunken -font $bfont -textvariable result3

pack .m2 -side left -fill both
pack .m1.label4 .m1.result4 -fill both
pack .m2.r -fill both
pack .m2.c -fill both
pack .m2.b -fill both
pack .m1 -side left -fill both
pack .m1.label1  -fill both
pack .m1.result1  -fill both
pack .m1.label2  -fill both
pack .m1.result2  -fill both
pack .m1.label3  -fill both
pack .m1.result3  -fill both
}
  proc balloon_aux {w msg} {
      set t .balloon_help
      catch {destroy $t}
      toplevel $t
      wm overrideredirect $t 1
      if {$::tcl_platform(platform) == "macintosh"} {
       unsupported1 style $t floating sideTitlebar
      }
      pack [label $t.l -text $msg -relief groove -bd 1 -bg gold] -fill both
      set x [expr [winfo rootx $w]+6+[winfo width $w]/2]
      set y [expr [winfo rooty $w]+6+[winfo height $w]/2]
      wm geometry $t +$x\+$y
      bind $t <Enter> {after cancel {catch {destroy .balloon_help}}}
      bind $t <Leave> "catch {destroy .balloon_help}"
  }
#    pack [button .b -text tryme -command {puts "you did it!"}]
#    balloon_help .b "Text that describes\nwhat the button does"

# Top frame is a menubar
# there is more magic that you can do with this
# build widget .m
frame .m \
        -bg {navy} \
        -borderwidth {2} \
        -relief {groove} 

button .m.help -bitmap @$ICONDIR/info.icon -relief {raise} -font $bfont -background navy -fg white -command {Help logs}

button .m.q -text "Exit" -relief {raise} -font $bfont -background red -fg white -command exit
 
 pack .m.help .m.q -side left -fill both -expand 1
 balloon_help .m.help "click for information"
 balloon_help .m.q "click to Exit this widget"

 entry .e -textvar cmd -font $bfont
 bind .e <Key-Return> {go %W}
 text .t -wrap word -font $bfont -height 3 -width 1 

 proc go {w} {
    global cmd
     set i [llength $cmd]
     if {$i==2} {
	 set cmd1 [lindex $cmd 0]
	 set cmd2 [lindex $cmd 1]
	 set res [exec ./metwind $cmd1 $cmd2]
     } else {
	 set res [exec ./metwind $cmd]
     }
     .t insert end $res
     .t yview end
     set cmd ""
 }

 eval pack [winfo children . ] -fill both -expand 1
 focus .e

proc Help {sel} {
        global cmd
# long lines to allow msg to format things

       set h(logs) {Meteorological Measurement System(MET3) 
Command Guide

Example: *0100Q3 <CR>     - this will give you the temp.

These are just a few of the commands available. 

*0100Q3  temperature measurement.
*0100P3  pressure measurement.
*0100RH  humidity measurement. */
*0100UN  pressure determination.
*9900VR  stop any commands in progress, reset.

Please consult your manual for more available commands.
===============================
*0100EW    Enable EPROM write for one command string. 
	   May be a 99 command ( *9900EW ) for global commands.

Example: *0100EW*0100UN=x   where x=1(psi),2(mbar),3(bars)..etc.

Other change parameter commands may be issued. Consult 
you manual.

-------------------------------------------------------
If you have a wind sensor as well. 

Example: wind W5     - WindSensor avrg., direction, speed.

These commands may be issued.

wind D   WindSensor Diagnostics.
wind H   WinddSensor heater control  0=off, 1=on. 
wind I   WindSensor Identity.
wind W5  WindSensor avrg., direction, speed. 
wind Ux  WindSensor units x  0=miles,1=knots 
	                     2=kilometers,3=meters/hr.

Consult your manual for other commands available.

}

 if { $sel == "commands" } {
   set h(commands) {Key    Alias
 }
 foreach name [lsort [array names cmd]] {
   set h(commands) [format "%s\n%-7s\t%s" $h(commands) $name $cmd($name)]
 }
 }
 tk_dialog .help "Information" $h($sel) {} -1 OK
}
#
# This is a standard bit of code, modified to use my font
# dialog.tcl --
#
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#
# $Header: /user6/ouster/wish/library/RCS/dialog.tcl,v 1.4 93/08/16 16:59:52 ouster Exp $ SPRITE (Berkeley)
#
# Copyright (c) 1992-1993 The Regents of the University of California.
# All.vpeople.rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above cop.vpeople.right notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#

#
# tk_dialog:
#
# This procedure displays a dialog box, waits for a button in the dialog
# to be invoked, then returns the index of the selected button.
#
# Arguments:
# w -           Window to use for dialog top-level.
# title -       Title to display in dialog's decorative frame.
# text -        Message to display in dialog.
# bitmap -      Bitmap to display in dialog (empty string means none).
# default -     Index of button that is to display the default ring
#               (-1 means none).
# args -        One or more strings to display in buttons across the
#               bottom of the dialog box.

proc tk_dialog {w title text bitmap default args} {
    global tk_priv

    set bfont {-*-lucida-bold-r-*-sans-12-*-*-*-*-*-*-*}

    set ICONDIR /usr2/fs/fsvue/images
    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w $title
    wm iconbitmap $w @$ICONDIR/vlb.icon
    wm iconname $w {VLBIIE}

    frame $w.top -relief raised -bd 1 -bg blue
    pack $w.top -side top -fill both
    frame $w.bot -relief raised -bd 1 -bg blue
    pack $w.bot -side bottom -fill both

    # 2. Fill the top part with bitmap and message.

    message $w.msg -width 5i -text $text -font $bfont
    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 5m -pady 5m
    if {$bitmap != ""} {
        label $w.bitmap -bitmap $bitmap
        pack $w.bitmap -in $w.top -side left -padx 5m -pady 5m
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set i 0
    foreach but $args {
        button $w.button$i -text $but -command "set tk_priv(button) $i"
        if {$i == $default} {
            frame $w.default -relief sunken -bd 1 -bg blue
            raise $w.button$i $w.default
            pack $w.default -in $w.bot -side left -expand 1 -padx 3m -pady 2m
            pack $w.button$i -in $w.default -padx 2m -pady 2m \
                    -ipadx 2m -ipady 1m
            bind $w <Return> "$w.button$i flash; set tk_priv(button) $i"
        } else {
            pack $w.button$i -in $w.bot -side left -expand 1 \
                    -padx 3m -pady 3m -ipadx 2m -ipady 1m 
        }
        incr i
    }

    # 4. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    wm withdraw $w
    update idletasks
    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
            - [winfo vrootx [winfo parent $w]]]
    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
            - [winfo vrooty [winfo parent $w]]]
    wm geom $w +$x+$y
    wm deiconify $w

    # 5. Set a grab and claim the focus too.

#    set oldFocus [focus]
#    grab $w
#    focus $w

    # 6. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.

    tkwait variable tk_priv(button)
    destroy $w
#    focus $oldFocus
    return $tk_priv(button)
}
startwx
while {1} {

set result4 [exec vueinfo time]
set result1 [exec ./metwind temp]
set result2 [exec ./metwind pres]
set result3 [exec ./metwind humi]

update
}
